/**
 * 
 */
package email.controller;

import javax.swing.JTable;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import email.model.Email;
import email.view.MailTable;
import email.view.SendMailView;

/**
 * @author Dominik Roth
 * Shows the selected mail in a new View.
 */
public class ShowMailListener implements ListSelectionListener {
	
	private JTable table;

	public ShowMailListener(JTable table)
	{
		this.table = table;
	}
	
	public void valueChanged(ListSelectionEvent e) {
		if (!e.getValueIsAdjusting()) {
			try{
			int selected = table.getSelectedRow();
			MailTable tableModel = (MailTable)table.getModel();
			Email mail = tableModel.getRow(selected);
			new SendMailView(mail);
			}catch(ArrayIndexOutOfBoundsException ex)
			{
				
			}
		}
	}

}
